package com.googlecode.imanager.client.form;

import com.googlecode.imanager.client.Container;
import com.googlecode.imanager.client.bridge.form.IFileButton;
import com.googlecode.imanager.client.io.File;
import com.googlecode.imanager.client.util.Utils;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class FileButton extends Button implements IFileButton {

    private static final long serialVersionUID = 1L;

    private transient File[] files;
    private FileSelectionMode selectionMode;
    private Boolean multiple;
    
    public FileButton() {
    }
    
    public FileButton(Container parent) {
        this();
        setParent(parent);
    }
    
    protected void onFileSelected(File[] files){
        this.files = files;
    }

    public FileSelectionMode getSelectionMode() {
        return selectionMode;
    }

    public void setSelectionMode(FileSelectionMode selectionMode) {
        if (selectionMode == null){
            selectionMode = FileSelectionMode.DEFAULT;
        }
        if (this.selectionMode != selectionMode){
            this.selectionMode = selectionMode;
            getBridge().setSelectionMode(selectionMode);
        }
    }

    public void setMultiple(Boolean multiple) {
        if (!Utils.isEquals(this.multiple, multiple)){
            this.multiple = multiple;
            getBridge().setMultiple(multiple);
        }
    }

    public Boolean getMultiple() {
        return multiple;
    }

    public boolean isMultiple() {
        return multiple == null ? false : multiple;
    }

    public File[] getSelectedFiles() {
        return files;
    }

    public void setSelectedFiles(File[] files) {
        this.files = files;
    }

    @Override
    protected IFileButton getBridge() {
        return (IFileButton) lookupBridge();
    }
    
    @Override
    public FileButton clone() {
        return (FileButton) super.clone();
    }

}
